package com.lz.comm.extension

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File

val GSON: Gson by lazy { GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss:SSS").create() }

/*fun Any.toGsonString(): String = GSON.toJson(this)

inline fun <reified T> String.jsonToBean(): T? = GSON.fromJson(this, T::class.java)

inline fun <reified T> String.jsonToList(): List<T> = GSON.fromJson(this, object : TypeToken<List<T>>() {}.type)*/

//json请示转换类型

fun String.toJsonRequestBody(): RequestBody = RequestBody.create(MediaType.parse("application/json"), this)

fun String.toTextRequestBody(): RequestBody = RequestBody.create(MediaType.parse("text/plain"), this)

fun File.toImgRequestBody(): RequestBody = RequestBody.create(MediaType.parse("image/jpg"), this)

fun File.toZipRequestBody(): RequestBody = RequestBody.create(MediaType.parse("application/zip"), this)

fun File.toImgPart(name: String): MultipartBody.Part = MultipartBody.Part.createFormData(name, this.name, this.toImgRequestBody())

fun File.toZipPart(name: String): MultipartBody.Part = MultipartBody.Part.createFormData(name, this.name, this.toZipRequestBody())




